package ran.friend.controller.exam;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ran.controller.BaseController;
import ran.entity.Result;
import ran.friend.domain.exam.dto.ExamQueryDTO;
import ran.friend.domain.exam.vo.ExamVO;
import ran.entity.TableDataInfo;
import ran.friend.service.exam.IExamService;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ran
 * Date: 2025-11-06
 * Time: 15:00
 */
@RestController
@RequestMapping("/exam")
public class ExamController extends BaseController {
    @Autowired
    IExamService examService;
    // 所有竞赛列表展示
    @GetMapping("/semiLogin/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO) {
        List<ExamVO> list = examService.list(examQueryDTO);
        return toTableDataInfo(list);
    }

    @GetMapping("/semiLogin/redis/list")
    public TableDataInfo redisList(ExamQueryDTO examQueryDTO) {
       return examService.redisList(examQueryDTO);
    }

    // 获取竞赛中第一道题目的id 从Redis中查询, 没有的话从数据库查,再刷新缓存
    // 将题目id的集合存储在Redis中 key -> e:q:l:examId   val -> questionId   类型:list
    @GetMapping("/getFirstQuestion")
    public Result<String> getFirstQuestion(Long examId) {
        return Result.ok(examService.getFirstQuestion(examId));
    }

    // 将题目id的集合存储在Redis中 key -> e:q:l:   val -> questionId   类型:list
    // 返回给前端一个String类型的id, 因为太长了
    @GetMapping("/preQuestion")
    public Result<String> preQuestion(Long examId, Long questionId) {
        return Result.ok(examService.preQuestion(examId,questionId));
    }
    @GetMapping("/nextQuestion")
    public Result<String> nextQuestion(Long examId, Long questionId) {
        return Result.ok(examService.nextQuestion(examId,questionId));
    }
}
